package com.aaa.three.controller;

import com.aaa.three.aop.Log;
import com.aaa.three.pojo.domain.AdminInfo;
import com.aaa.three.pojo.domain.AdminLogin;
import com.aaa.three.pojo.vo.AdminVO;
import com.aaa.three.result.AjaxResult;
import com.aaa.three.service.AdminService;
import com.aaa.three.util.OSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @PACKAGE_NAME: com.aaa.three.controller
 * @NAME: AdminController
 * @USER: Tprairie
 * @DATE: 2022/1/10
 * @PROJECT_NAME: three
 */
@RestController
@RequestMapping("admin")
public class AdminController {

    @Autowired
    public AdminService adminService;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private OSSUtil ossUtil;

    @RequestMapping("login")
    @Log("登录")
    public AjaxResult login(String username , String password){
        return adminService.login(username,password);
    }

    @RequestMapping("getInfo")
    public AjaxResult getInfo(){
        return adminService.getInfo();
    }

    @RequestMapping("loginOut")
    public AjaxResult logOut(HttpServletRequest request){
        request.getSession().removeAttribute("apassword");
        request.getSession().invalidate();
        return AjaxResult.success();
    }

    @RequestMapping("checkPass")
    public AjaxResult checkPass(AdminLogin adminLogin){
        return adminService.checkPass(adminLogin);
    }

    @RequestMapping("updatAdminInfo")
    @Log("修改个人信息")
    public AjaxResult updatAdminInfo(AdminVO adminVO){
        return adminService.updatAdminInfo(adminVO);
    }

    @RequestMapping("updateHeadImg")
    @Log("修改头像")
    public AjaxResult updateHeadImg(AdminVO adminVO , MultipartFile file){
        String path = ossUtil.upLoadOSS(file);
        adminVO.setAphoto(path);
        return adminService.updateHeadImg(adminVO);
    }



}
